<template>
	<view class="goods_detail">
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :interval="3000" :duration="1000">
			<swiper-item>
				<image src="../../static/4a91ad8e67b2c92de2418e5913767a47.jpg" mode="aspectFill"></image>
			</swiper-item>
			<swiper-item>
				<image src="../../static/254542c348e0401b7133784724f50cea.jpg" mode="aspectFill"></image>
			</swiper-item>
		</swiper>

		<!-- 商品标题 -->
		<view class="box1">
			<view class="price">
				<text>￥{{detail.sell_price}}</text>
				<text>￥{{detail.market_price}}</text>
			</view>
			<view class="name">
				{{detail.title}}
			</view>
		</view>
		<!-- 分割线 -->
		<view class="line"></view>

		<!--  -->
		<view class="box2">
			<text>货号: {{detail.goods_no}}</text>
			<text>库存: {{detail.stock_quantity}}</text>
		</view>

		<!-- 分割线 -->
		<view class="line"></view>

		<!--  -->
		<view class="box3">
			<view class="title">
				详情介绍
			</view>
			<view class="content">
				<rich-text :nodes="this.desc.content"></rich-text>
			</view>
		</view>

		<!-- 底部导航 -->
		<view class="goods_nav">
			<uni-goods-nav :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick"
				@buttonClick="buttonClick" />
		</view>

	</view>
</template>

<script>
	import uniGoodsNav from '@/components/uni-goods-nav/uni-goods-nav.vue'
	export default {
		components: {
			uniGoodsNav
		},
		data() {
			return {
				id: 0,
				swipers: [],
				detail: {},
				desc: {},
				options: [{
					icon: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/uni-ui/goodsnav/kefu.png',
					text: '客服'
				}, {
					icon: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/uni-ui/goodsnav/dianpu.png',
					text: '店铺'
				}, {
					icon: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/uni-ui/goodsnav/carts.png',
					text: '购物车',
					info: 0
				}, ],
				buttonGroup: [{
						text: '加入购物车',
						backgroundColor: '#ff0000',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: '#ffa200',
						color: '#fff'
					}
				]
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getGoodSwiper()
			this.getDetial()
			this.getDesc()
		},
		methods: {
			// 获取商品详情轮播图
			async getGoodSwiper() {
				const res = await this.$myRequest({
					url: '/getthumimages/' + this.id
				})
				this.swipers = res.data.message
			},
			// 获取库存等内容
			async getDetial() {
				const res = await this.$myRequest({
					url: '/goods/getinfo/' + this.id
				})
				this.detail = res.data.message[0]
			},
			// 获取描述内容
			async getDesc() {
				const res = await this.$myRequest({
					url: '/goods/getdesc/' + this.id
				})
				this.desc = res.data.message[0]
			},
			// 底部导航的方法
			onClick(e) {
				uni.showToast({
					title: `点击${e.content.text}`,
					icon: 'none'
				})
			},
			buttonClick(e) {
				console.log(e)
				this.options[2].info++
			}
		}
	}
</script>

<style lang="scss">
	swiper {
		height: 700rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.box1 {
		padding: 10px;

		.price {
			font-size: 35rpx;
			color: $shop-color;
			line-height: 80rpx;

			text:nth-child(2) {
				margin-left: 20rpx;
				color: #C8C7CC;
				font-size: 28rpx;
				text-decoration: line-through;
			}
		}

		.name {
			font-size: 30rpx;
			line-height: 60rpx;
		}
	}

	.box2 {
		display: flex;
		flex-direction: column;
		padding-left: 10rpx;
	}

	.box3 {
		.title {
			border-bottom: 2rpx solid #F1F1F1;
			font-size: 32rpx;
			padding-left: 10rpx;
			line-height: 70rpx;
		}

		.content {
			padding-left: 10rpx;
			font-size: 32rpx;
			line-height: 50rpx;
		}
	}

	.line {
		width: 100%;
		height: 5rpx;
		background-color: #999999;
	}

	.goods_nav {
		// 固定定位
		position: fixed;
		bottom: 0;
		width: 100%;
	}
</style>
